package com.rdc.qingkou.presenter;

import com.rdc.qingkou.contract.ChangePasswordContract;
import com.rdc.qingkou.entity.ModifyUserInfoResult;
import com.rdc.qingkou.entity.Result;
import com.rdc.qingkou.model.ChangePasswordModel;
import com.rdc.qingkou.model.imodel.OnHttpCallBack;

/**
 * Created by WaxBerry on 2017/11/13.
 */

public class ChangePasswordPresenter implements ChangePasswordContract.IPresenter {

    private ChangePasswordContract.IModel mIModel;   //M层
    private ChangePasswordContract.IView mIView;  //V层

    public ChangePasswordPresenter(ChangePasswordContract.IView mIView){
        this.mIView = mIView;
        mIModel = new ChangePasswordModel();
    }

    @Override
    public void showPassword(Integer userId) {

        mIModel.showPassword(userId, new OnHttpCallBack<ModifyUserInfoResult>() {
            @Override
            public void onSuccessful(ModifyUserInfoResult modifyUserInfoResult) {
                mIView.getPassword(modifyUserInfoResult);
            }

            @Override
            public void onFaild(String errorMsg) {
                mIView.showInfo(errorMsg);
            }
        });
    }

    /**
     * 修改密码
     *
     * @param userId
     * @param oldPassword
     * @param newPassword
     * @param confirmPassword
     */
    @Override
    public void changePassword(String userId, String oldPassword, String newPassword, String confirmPassword) {

        mIModel.changePassword(userId, oldPassword, newPassword, confirmPassword, new OnHttpCallBack<Result>() {
            @Override
            public void onSuccessful(Result result) {
                mIView.showModifyResult(result);
            }

            @Override
            public void onFaild(String errorMsg) {
                mIView.showInfo(errorMsg);
            }
        });

    }
}
